package com.rc.web.mapper;

import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.rc.pojo.dto.knowLedgvideo.KnowledgeVideoPageQuery;
import com.rc.pojo.po.KnowledgeVideo;
import com.rc.pojo.vo.knowledgevideo.KnowledgeVideoPageVO;

import java.util.List;

import static com.rc.pojo.po.table.IllTableDef.ILL;
import static com.rc.pojo.po.table.KnowledgeVideoTableDef.KNOWLEDGE_VIDEO;

/**
 * 知识视频表 映射层。
 * 提供知识视频相关的数据库操作接口
 */
public interface KnowLedgeVideoMapper extends BaseMapper<KnowledgeVideo> {

    /**
     * 分页查询知识视频
     * @param query 分页查询条件
     * @return 分页结果
     */
    default Page<KnowledgeVideoPageVO> selectPage(KnowledgeVideoPageQuery query){
        return paginateAs(query.getCurrent(),query.getPageSize(), QueryWrapper.create()
                .select(KNOWLEDGE_VIDEO.ALL_COLUMNS, ILL.NAME.as("illName"))
                .join(ILL).on(ILL.ID.eq(KNOWLEDGE_VIDEO.ILL_ID))
                .where(KNOWLEDGE_VIDEO.TITLE.like(query.getTitle()))
                ,KnowledgeVideoPageVO.class);
    }

    /**
     * 根据病害ID列表查询知识视频
     * @param illIds 病害ID列表
     * @return 知识视频列表
     */
    default List<KnowledgeVideo> selectListByIllIds(List<Long> illIds){
        return selectListByQuery(QueryWrapper.create()
                .where(KNOWLEDGE_VIDEO.ILL_ID.in(illIds))
        );
    }
}
